package ch.bfh.abcmmh.model.cars.specialVehicles;

import java.util.Observable;

import ch.bfh.abcmmh.controller.operating.clock.Clock;
import ch.bfh.abcmmh.exceptions.EndofStreetExeption;
import ch.bfh.abcmmh.exceptions.WrongSpeedException;
import ch.bfh.abcmmh.model.cars.Vehicle;
import ch.bfh.abcmmh.model.streetutils.Street;

public class Truck extends Vehicle {

	private static int TRUCKLENGTH = 55;

	public Truck(Street street, int startSpeed, int position, int carNumber, int streetNumber, float maybe) {
		super(street, startSpeed, position, carNumber, TRUCKLENGTH, streetNumber, maybe);
		this.maxSpeed = 110;
	}

	@Override
	public void update(Observable o, Object arg) {
		
		this.accelerate();
		
		this.simpleSwichLane2();

		this.slowdown(this.calculateSlowdown());

		if (calculateMaybe() &&this.speed>40) {
			this.dawdle();
		}

		try {
			this.move();
		} catch (WrongSpeedException e) {
		} catch (EndofStreetExeption e) {
			Clock c = (Clock) o;
			c.deleteObserver(this);
			this.onStreet= false;
		}
	}

}
